/* File Info 
 * Author:      cknight 
 * CreateTime:  2021/1/20 下午1:18:52 
 * LastEditor:  cknight 
 * ModifyTime:  2021/1/22 上午10:11:40 
 * Description: login事件回调
 */
const { Contact, Message, ScanStatus, Wechaty } = require("wechaty");
const schedule = require("../schedule");
const config = require("../config");
const untils = require("../utils");
const superagent = require("../superagent");
const bot = require("../app");
async function onLogin(user) {
    console.log(`您的贴心小助理${user}登录了`);
    //创建定时发送群消息任务
    await onRoom();
}
/**
 * 9点定时给指定群发送消息
 */
async function onRoom() {
    //匹配规则可参考 schedule/index.js
    const time = "0 0 10 * * *";
    schedule.setSchedule(time, async() => {
        let today = await untils.formatDate(new Date()); //获取今天的日期
        let one = await superagent.getOne(); //获取每日一句
        let englishData = await superagent.getEnglishOne(); //英语一句话
        let english = `en：${englishData.en}\nzh：${englishData.zh}`;
        let poison = await superagent.getSoup(); //毒鸡汤
        let str = `${today}\n元气满满的一天开始啦,要加油噢^_^\n\n每日一句：\n${one.word}\n\n英语一句话：\n${english}\n\n毒鸡汤：\n${poison}`;
        if (Array.isArray(config.WEBROOM)) {
            config.WEBROOM.map(async item => {
                let room = await bot.Room.find({
                    topic: item
                });
                await room.say(str);
            })
        } else {
            const room = await bot.Room.find({
                topic: config.WEBROOM
            });
            await room.say(str);
        }
    });
}
module.exports = onLogin;